package com.sqx.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.dao.UserVipDao;
import com.sqx.modules.app.entity.UserVip;
import com.sqx.modules.app.service.UserVipService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class UserVipServiceImpl extends ServiceImpl<UserVipDao, UserVip> implements UserVipService {

    @Override
    public UserVip selectUserVipByUserId(Long userId) {
        QueryWrapper<UserVip> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public Result isUserVip(Long userId) {
        boolean isVip = false;
        //查询用户是否是会员
        QueryWrapper<UserVip> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        UserVip userVip = baseMapper.selectOne(queryWrapper);
        if (userVip != null) {
            if (userVip.getIsVip() == 1) {
                isVip = true;
            }
        }
        return Result.success().put("data", isVip);
    }


}
